package com.zonski.jbots.game.collision;

import com.zonski.jbots.engine.*;
import com.zonski.jbots.game.JBotsConstants;

/**
 * Created by IntelliJ IDEA.
 * User: Chris Glover
 * Date: 7/06/2004
 * Time: 10:12:53
 * To change this template use Options | File Templates.
 */
public class ChargeBoostingCollisionEffect implements CollisionEffect
{
    private int maximum;

    public ChargeBoostingCollisionEffect(int maximum)
    {
        this.maximum = maximum;
    }

    public int getCollisionType(Entity entity, Entity with)
    {
        return SIMPLE_COLLISIONS;
    }

    public boolean apply(Entity entity, Engine engine, CollisionData collision)
    {
        Entity with = collision.with;

        // boost the entities battery capacity up to the maximum then die
        int amount = with.getMaxCharge();
        int maxCharge = entity.getMaxCharge();
        if(maxCharge < this.maximum)
        {
            int newMaxCharge = Math.min(maxCharge + amount, this.maximum);
            entity.setMaxCharge(newMaxCharge);
        }
        entity.setCharge(entity.getCharge() + with.getCharge());
        engine.getDevice().play(JBotsConstants.CAPACITY, 1);
        with.setRemovable(true);
        return false;
    }
}
